<?php 
include('./fun.php');
$conn=my_sql($cfg);
$re=adm_login();
if($re['err']=='no_login'){no_login();}
$id=g('id');if(!$id or !is_numeric($id)){$id=0;}
if($id){
$sql='select * from '.$cfg['e'].'help where id="'.$id.'"';
$l=db1($sql);
}
?>
<style></style>

<help_edit_box>
<l><text>标题</text>
<input placeholder="帮助的标题" value="<?php echo $l['title']?>" c="title" need="1">
</l>

<l><text>分类</text>
<input placeholder="帮助的分类" value="<?php echo $l['c']?>" c="c" need="1">
</l>

<l><text>标签</text>
<input placeholder="标签，请用,进行间隔" value="<?php echo $l['tag']?>" c="tag">
</l>

<l><text>摘要</text>
<input placeholder="文档摘要" value="<?php echo $l['info']?>" c="info">
</l>

<l><text>文档</text>
<div id="editor"><?php echo $l['html']?></div>
</l>

<l><a class="green" onclick="submit($(this))">提交</a></l>
</help_edit_box>



<script>
window.editor;

$(document).ready(function(){
ClassicEditor.create( document.querySelector('#editor'),{language:'zh-cn'}).then( editor => {
        window.editor = editor; // Save for later use.
        
        $('.ck-file-dialog-button button').remove()
       $('.ck-file-dialog-button').html('<button><svg class="ck ck-icon ck-button__icon" viewBox="0 0 20 20"><path d="M6.91 10.54c.26-.23.64-.21.88.03l3.36 3.14 2.23-2.06a.64.64 0 0 1 .87 0l2.52 2.97V4.5H3.2v10.12l3.71-4.08zm10.27-7.51c.6 0 1.09.47 1.09 1.05v11.84c0 .59-.49 1.06-1.09 1.06H2.79c-.6 0-1.09-.47-1.09-1.06V4.08c0-.58.49-1.05 1.1-1.05h14.38zm-5.22 5.56a1.96 1.96 0 1 1 3.4-1.96 1.96 1.96 0 0 1-3.4 1.96z"></path></svg></button>');
    
    $('.ck-file-dialog-button').click(function(){
    win({title:'选择图片',url:'select_img.php?action=insert_img($(this))',width:1000});
    })
    
} ).catch( error => {
        console.error( error );
    } );

});

function insert_img(o){
var img=o.attr('img_750');
const content = '<p><img src="'+img+'" width="100%"></img></p>';
const viewFragment = window.editor.data.processor.toView( content );
const modelFragment = window.editor.data.toModel( viewFragment );

window.editor.model.insertContent( modelFragment );
   
}


function submit(){
var re=form_data($('help_edit_box input'));
if(re.can==0){
var data=re.data;
var val=window.editor.getData();
if(!val){msg('请输入帮助内容');return;}
data['html']=val;
post('help_edit',data,'<?php echo $l['id']?>',function(res){
msg('保存成功');
main_load();

});
}
}


</script>